<?php
/*
	SytemLog definition
	author xuebangshu
	since 2009-06-22
*/

require_once BaseUtil::getModulePath("base")  .  '/services/BaseService.php';
require_once BaseUtil::getModulePath("systemlog")  .  '/models/LogDao.php';

class SystemLogService extends BaseService {
    private $logDao;

    public function  __construct() {
        parent::__construct();
        $this->logDao=new LogDao();
        $this->logDao->setDb($this->db);
    }
    
    public function insertSystemLog($action,$userId,$actionResult=array(),$actionCondition = array(),$actionType=2){
        $log=array();
        $log['action']=$action;
        $result = array();
        if(!empty($actionResult)){
            $result['data'] = $actionResult;
        }    
      	if(!empty($actionCondition)){
            $result['condition'] = $actionCondition;
        }        
        $log['action_result']=json_encode($result);
        $log['user_id']=$userId;
        $log['action_type']=$actionType;
        $logId = $this->logDao->addLog($log);
    }

    public function getSystemLogById($id){
        return $this->logDao->getSystemLogById($id);
    }

    public function deleteSystemLog($id){
        $this->logDao->deleteSystemLog($id);
    }

    public function deleteSystemLogs($ids){
        foreach($ids as $id){
            $this->logDao->deleteSystemLog($id);
        }
    }
}
?>